//
//  NYSearchManager.m
//  Nooryes
//
//  Created by baken on 2020/3/9.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYSearchManager.h"
#import "NYTopicCategoryModel.h"
#import "NYArticleListModel.h"
#import "NYTopicListModel.h"
#import "NYSearchUserModel.h"

@implementation NYSearchManager

+(void)getHotTopicListWithPage:(NSString *)page andCompletionHandle:(void (^)(NYTopicListModel * _Nonnull, NSError * _Nonnull))complete{
       [self GET:[NSString stringWithFormat:@"%@%@",Api_URL,kGetHotTopicList]
       parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
            NYTopicListModel *model = [NYTopicListModel mj_objectWithKeyValues:responseObj];
            if (model.code != 0) {
                error = [self createError:model.msg];
            }
            complete(model,error);
        }];
}

+(void)getHotCategoryListWithPage:(NSString *)page andCompletionHandle:(void (^)(NYTopicCategoryModel * _Nonnull, NSError * _Nonnull))complete{
       [self GET:[NSString stringWithFormat:@"%@%@",Api_URL,kGetHotCategoryList]
       parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
            NYTopicCategoryModel *model = [NYTopicCategoryModel mj_objectWithKeyValues:responseObj];
            if (model.code != 0) {
                error = [self createError:model.msg];
            }
            complete(model,error);
        }];
}

+(void)getSearchUserListWithKeys:(NSString *)keys andPage:(NSString *)page andCompletionHandle:(void (^)(NYSearchUserModel * _Nonnull, NSError * _Nonnull))complete{
     
       [self GET:[NSString stringWithFormat:@"%@%@?p=%@&keys=%@",Api_URL,kGetSearchUserList,page,keys]
       parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
            NYSearchUserModel *model = [NYSearchUserModel mj_objectWithKeyValues:responseObj];
            if (model.code != 0) {
                error = [self createError:model.msg];
            }
            complete(model,error);
        }];
}

+(void)getSearchAriticlesWithKeys:(NSString *)keys andType:(NSString *)type andPage:(NSString *)page andCompletionHandle:(void (^)(NYArticleListModel * _Nonnull, NSError * _Nonnull))complete{
       [self GET:[NSString stringWithFormat:@"%@%@?p=%@&type=%@&keys=%@",Api_URL,kGetSearchArticleList,page,type,keys]
       parameters:nil
    completionHandler:^(id responseObj, NSError *error) {
            NYArticleListModel *model = [NYArticleListModel mj_objectWithKeyValues:responseObj];
            if (model.code != 0) {
                error = [self createError:model.msg];
            }
            complete(model,error);
        }];
}

+ (void)getSearchTopicListWithKeys:(NSString *)keys andType:(NSString *)type andPage:(NSString *)page andCompletionHandle:(void (^)(NYTopicListModel *model, NSError *error))complete{
    [self GET:[NSString stringWithFormat:@"%@%@?p=%@&type=%@&keys=%@",Api_URL,kGetSearchTopicList,page,type,keys]
   parameters:nil
completionHandler:^(id responseObj, NSError *error) {
        NYTopicListModel *model = [NYTopicListModel mj_objectWithKeyValues:responseObj];
        if (model.code != 0) {
            error = [self createError:model.msg];
        }
        complete(model,error);
    }];
}

@end
